import time
import uuid

from appium.webdriver.common.appiumby import AppiumBy
from ...constants.common_sequence import SWITCH_ENV
from ...exception.customer_exception import CustomerException

from ...function.common_function import CommonFunction
from ...models.enums.app_http_code_enum import AppHttpCodeEnum

"""
Description：这里是在付款完成后的统计金额【餐票，标签，小票打印】
"""


class CasherDetailPage(object):

    def __init__(self, client):
        self.client = client
        self.driver = client.driver

    """
    业务方法
    """

    def time_wait(self, num):
        """
        时间等待
        Params:
        -num: 时间
        """
        self.driver.implicitly_wait(num)
        return self

    def time_sleep(self, seconds):
        """
        时间睡眠
        Params:
        -seconds:时间
        """
        time.sleep(seconds)
        return self

    def screen_shoot(self, filename, path):
        """
        屏幕截图
        Params:
        -filename:文件名称
        -path:路径
        """
        CommonFunction(self.driver).screen_shoot(filename=filename, path=path)
        return self

    def print_meal_ticket(self):
        """
        餐票打印
        """
        element = self.driver.find_element(AppiumBy.ID, f'{SWITCH_ENV}:id/ll_print_ticket')
        element.click()

    def print_label(self):
        """
        标签打印
        """
        element = self.driver.find_element(AppiumBy.ID, f'{SWITCH_ENV}:id/ll_print_label')
        element.click()

    def print_receipt(self):
        """
        小票打印
        """
        element = self.driver.find_element(AppiumBy.ID, f'{SWITCH_ENV}:id/ll_print_receipts')
        element.click()

    def close(self):
        """
        关闭弹框
        """
        time.sleep(3)
        try:
            self.driver.find_element(AppiumBy.ID, f'{SWITCH_ENV}:id/iv_close').click()
        except Exception as e:
            raise CustomerException(AppHttpCodeEnum.BEHIND_PAY_CLOSE_POPUP_FILE)
        from ...page.order_page.order_page import OrderPage
        return OrderPage(self.client)
